docs: give every package a doc comment and enforce it - #753
Conversation
pkg.go.dev showed "There is no documentation for this package" for the module root because there was none: the module root is package main, the only comment above the package clause is the SPDX header, and a blank line separates it, so Go does not read it as a doc comment. `go doc .` returned nothing at all. Nine of fifteen packages were in the same state — the root plus cli, config, core, metrics, middlewares, static, test and web. Add a doc.go per undocumented package describing what it actually does. The root one doubles as the command's documentation, which is what pkg.go.dev renders for a command module. Enforce it so it cannot drift again. revive's package-comments rule was present but disabled, and even after enabling it the rule stayed silent: the `comments` exclusion preset filtered it out. Dropping that preset makes the rule effective but also surfaces 50 findings about missing comments on exported symbols, which is a separate and much larger question — so the exported-symbol rule keeps its exemption through a targeted exclusion, and only the package-comment requirement becomes blocking. Verified in both directions rather than assumed: with the doc files in place golangci-lint reports 0 issues, and removing a single doc.go produces exactly one finding, "should have a package comment". Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
There was a problem hiding this comment.
Automated approval for maintainer PR
All automated quality gates passed. See SECURITY_CONTROLS.md for compensating controls.
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #753 +/- ##
==========================================
- Coverage 87.66% 87.63% -0.04%
==========================================
Files 90 90
Lines 12058 12058
==========================================
- Hits 10571 10567 -4
- Misses 1196 1199 +3
- Partials 291 292 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|



Fixes the "no documentation" state on pkg.go.dev.
Why the page was empty
Not an indexing or license problem — there genuinely was no documentation.
go doc .returned nothing.The module root is
package main, and the only comment above the package clause is the SPDX header:Go treats a comment block as package documentation only when it is immediately adjacent to the
packageclause. The blank line separates it, so there was no doc comment. (The blank line is correct — without it pkg.go.dev would render the copyright header as the package description.)Nine of fifteen packages were in that state: the root plus
cli,config,core,metrics,middlewares,static,test,web. The packages added more recently (core/adapters/*,core/domain,core/ports,core/persist,test/testutil) already had comments.What this changes
A
doc.goper undocumented package, describing what it actually does rather than restating its name. The root one doubles as the command's documentation, which is what pkg.go.dev renders for a command module:Making it stick
Documentation that nothing enforces drifts back, which is how this happened: revive's
package-commentsrule was already in.golangci.yml— explicitlydisabled: true.Enabling it was not enough. The rule stayed silent because the
commentsexclusion preset filtered it out. Removing that preset makes the rule effective, but also surfaces 50 findings about missing comments on exported symbols — a separate and much larger question. So the exported-symbol rule keeps its current exemption through a targeted exclusion (text: '^exported: '), and only the package-comment requirement becomes blocking.Net config change is three lines:
Verification
Enforcement proven in both directions, not assumed:
golangci-lint run→ 0 issuesdoc.godeletedpackage-comments: should have a package commentAlso:
go doc .now returns the command documentation;go list -f '{{.Doc}}' ./...reports a synopsis for all 15 packages; build and vet clean under the default andintegrationtags;go test -race ./...14/14.Note that pkg.go.dev will still show the previous release until a tag containing this lands — the page currently serves v0.27.0 and has not yet picked up v0.28.0.